<#assign css> </#assign>
<#assign js> 
<script type="text/javascript">
	$(function(){
		frm.submit("iframe", "infoSaveForm");
		
		$("#tbody input[type='checkbox']").change(function(){
			var checked = $(this).is(':checked');
			
			checked_sub($(this).val(), checked);
			if (checked && $(this).attr("data-pid")) {
				checked_parent($(this).attr("data-pid"), checked);
			}
		});
		
		$("#checkAll").change(function() {
			$("#tbody input[type='checkbox']").prop("checked", $(this).is(':checked'));
		});
	});
	
	var checked_sub = function(id, checked) {
		$("input[data-pid='"+id+"']").each(function(){
			$(this).prop("checked", checked);
			
			checked_sub($(this).val(), checked);
		});
	}
	
	var checked_parent = function(id, checked) {
		$("input[value='"+id+"']").each(function(){
			$(this).prop("checked", checked);
			
			if ($(this).attr("data-pid")) {
				checked_parent($(this).attr("data-pid"), checked);
			}
		});
	}
</script>
</#assign>
<#import "/admin/common/home.html" as home>
<#import "/admin/common/tree.html" as tree>
<#escape x as (x)!"">
<@home.home pagecss=css pagejs=js>
<@home.tree />
<div class="page-dialog-content">
    <div class="panel-dialog">
		<form action="saveResource" id="infoSaveForm" method="post" class="form-inline">
			<input type="hidden" name="id" value="${info.id}"/>
			<div class="panel-dialog-body">
				<div class="search">
					<div class="form-group">
						<input type="text" id="tree-search-input" class="form-control" placeholder="请输入权限名称" />
					</div>
					<div class="form-group">
						<a href="javascript:;" class="btn btn-search" id="tree-search-btn">查询</a>
					</div>
				</div>
			
				<div class="main-container">
					<@tree.treeTable searchBtnId="tree-search-btn" searchInputId="tree-search-input" >
					<table class="table table-bordered table-hover">
						<thead class="thead thead-more">
							<tr>
								<th><label class="chkLab"><input type="checkbox" id="checkAll" />全选</label></th>
							</tr>
						</thead>
						<tbody class="tbody mod-tbody" id="tbody">
							<#list resources_1 as item1>
								<#assign resources_2 = resources_2_map[item1.id?c] />
								
								<tr data-tt-key="${item1.name}" data-tt-id="${item1.id}">
									<td><label class="chkLab"><input type="checkbox" name="resourceIds" <#if roleResourceIds?seq_contains(item1.id)>checked="checked"</#if> value="${item1.id}"/>${item1.name}</label></td>
								</tr>
								
								<#list resources_2 as item2>
									<#assign resources_3_parent = item1.id />
								
									<#if resources_2?size gt 1>
									<#assign resources_3_parent = item2.id />
									<tr data-tt-key="${item2.name}" data-tt-id="${item2.id}" data-tt-parent-id="${item1.id}">
										<td>
											<label class="chkLab"><input type="checkbox" name="resourceIds" <#if roleResourceIds?seq_contains(item2.id)>checked="checked"</#if> value="${item2.id}" data-pid="${item1.id}" />${item2.name}</label>
										</td>
									</tr>
									</#if>
									<#if item2.type == 2> <!-- type=2 为目录 -->
										<#assign resources_3 = resources_3_map[item2.id?c] />

										<#list resources_3 as item3>
											<tr data-tt-key="${item3.name}" data-tt-id="${item3.id}" data-tt-parent-id="${resources_3_parent}">
												<td>
													<label class="chkLab"><input type="checkbox" name="resourceIds" <#if roleResourceIds?seq_contains(item3.id)>checked="checked"</#if> value="${item3.id}" data-pid="${resources_3_parent}" />${item3.name}</label>
												</td>
											</tr>

											<#assign resources_4 = resources_4_map[item3.id?c] />
											<#if resources_4?? && resources_4?size gt 0>
												<tr data-tt-key="${item3.name}" data-tt-id="${item3.id}_b" data-tt-parent-id="${item3.id}">
													<td>
														<#list resources_4 as item4>
															<label class="chkLab">
																<input type="checkbox" name="resourceIds" <#if roleResourceIds?seq_contains(item4.id)>checked="checked"</#if> value="${item4.id}" data-pid="${item3.id}" />${item4.name}
															</label>
															<#if (item4_index != 0 && item4_index % 8 == 0)></br></#if>
														</#list>
													</td>
												</tr>
											</#if>
										</#list>
									</#if>

								</#list>
								
								
							
							</#list>
						</tbody>
					</table>
					</@tree.treeTable>
				</div>
			</div>
			
			<div class="panel-footer panel-dialog-footer panel-dialog-footer-fixed">
				<div class="text-right">
					<button id="dialog-btn-save" type="submit" class="btn btn-primary">保存</button>
					<button type="button" onclick="parent.layer.closeAll('iframe');" class="btn btn-default">取消</button>
				</div>
			</div>
			
		</form>
	</div>
</div>
</@home.home>
</#escape>
